<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('商品库')" />
	<th:block th:include="include :: businessCSS" />
	<style>
        .main-content{position: relative;}
        .topbtns{position:fixed;top: 0;width: 100%;z-index: 9999;background-color: #fff;}
		.preservationBtn{padding: 10px;margin: 0;position: fixed;top: 0;z-index: 9999;background: #fff;width: 100%;}
		.preservationBtn input{font-size: 16px;background-color: rgb(80, 138, 238);color: #fff;border: none;padding: 5px 30px;border-radius: 5px;cursor: pointer;}
		/* .layui-border-box{height: 350px !important;}
		.layui-table-body{height: 240px !important;} */
		.layui-table-tool-temp{padding-right: 30px;}
        .getDetailUpload,.getDetailUpload2{cursor: pointer;}
        .layui-table-tool-self{display: none;}
		textarea{width: 100%;border-color: #ddd;}

	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
        <div class="topbtns"><th:block th:include="include :: business_btn" /></div>
	    <div class="north" style="background-color: #fff;margin-top: 55px;">
			<div class="forminput"></div>
    	</div>
        <div style="width: 100%;height: 10px;background: #f6f6f6;"></div>
        <div>
            <table class="layui-hide" id="dhtable" lay-filter="dhtable"></table>
            <!-- <script type="text/html" id="barDh">
                <button class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" th:disabled="${enableEdit} == 1 ?false:true" lay-event="del">&nbsp;删除</button>
            </script> -->
            <script type="text/html" id="zjtoolbar">
                <div style="padding: 16px;display: flex;justify-content: space-between;">
                    <div style="font-weight: 700;font-size: 18px;">列表</div>
            		<div>
                        <!-- <button class="layui-btn layui-btn-normal dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="addbtn" id="btn-sh">新增</button> -->
                        <!-- <button class="layui-btn layui-btn-danger dhicon" th:classappend="${enableEdit} == 1 ?'':'layui-btn-disabled'" type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="mjbtn_save" id="btn-sh">删除</button> -->
            		</div>
            	</div>
            </script>
        </div>
        
        <th:block th:include="include :: pageFooter" /> 
    </form>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: inlineJS" />


<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "storage/dismounting",
    	prefix2 = ctx + "base/company";

	var fields = [[${fields}]];
    var fieldsList = [[${fieldsList}]];
	var fieldsHiddenList = [[${fieldsHiddenList}]];
	var moduleTable = [[${moduleTable}]];
	var enableEdit = [[${enableEdit}]];
    //母件表格基础信息
	var gridColumns = [[${gridColumns}]];
	var $,layer,form,table,nid,noTable;

    layui.use(['laydate','form','layer','jquery','util','element','upload','table'], function () {
        $ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element,upload = layui.upload,table = layui.table;
        beforeInit();//表单初始化之前的动作集合
		//初始化操作
		headcom3()
        nid=$('#nid').val()
        var listData1=[]
        $.get("/storage/dismounting/listbynid?nid="+nid,function(data){
            listData1=data.data
            // 初始化表格
            $.tablelist.init({
                elem: '#dhtable'
                , data: listData1
                , page: false
                , even: true
                , limit: 10000
                , totalRow: gridColumns.totalRow
                , cols: [gridColumns.gridBody]
                , toolbar: '#zjtoolbar'
                , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
                , height: '450'
                , done: function (res, curr, count) {
                    listData1 = table.cache.dhtable;//每次重载都赋值更新表缓存
                },success:function(a,b,c){
                }
            });
	    });

        $('body').on('blur','#destuffingNum',function(){
	    	var num=+$(this).val()
	    	var dataArr=table.cache["dhtable"]
	    	dataArr.map((v)=>{
                v.estimateNum=+v.sNum*num
	    	})
	    	table.reload('dhtable', {data: dataArr});
	    })

        //监听单元格编辑
        table.on('edit(dhtable)', function(obj){

        });

        //母件表格操作
        // table.on('toolbar(dhtable)', function (obj) {
        //     switch (obj.event) {
        //         case 'mjbtn_save':
        //             var xztable=table.checkStatus('dhtable').data
        //             listData1 = table.cache.dhtable;
        //             if(listData1.length<1){
        //                 layer.msg('请先选择数据')
        //             }else{
        //                 layer.confirm('是否确定删除', {btn : ['确定', '取消']}, function() {
        //                     xztable.forEach(item => {
	    //                     	listData1 = listData1.filter(items => items.guid!= item.guid);
	    //                     });
        //                     table.reload('dhtable', {data:listData1});
        //                 });
        //             }
        //             break;
        //     };
        // });

        $(".fieldsimg").each(function(){
	    	var id=$(this).attr('name')
            upload.render({
                elem: '#'+id+'_upimg',
	            url: '/system/fileinfo/uploadmailimg',
	            accept: 'images',
	    		before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                      console.log(index, file, result)
                    });
                },
	            done: function (res) {
                    //如果上传失败
                    if (res.errno > 0) {
                        return layer.msg('上传失败');
                    }else{
	    				layer.msg('上传成功');
	    				$('#'+id).val(res.data[0])
	    				layui.$('#'+id+'_upimg').find('.upicon').addClass('layui-hide')
	    				layui.$('#'+id+'_upimg').find('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.data[0]);
	    			}
                },error: function (err) {
                    //演示失败状态，并实现重传
	            	console.log(err)
                }
            });
        })


		$('.t_date').each(function(){
            var datetype=$(this).attr('datetype')
            laydate.render({
				elem:this
                ,type: datetype=='t_date'?'date':datetype=='t_datetime'?'datetime':datetype=='t_year'?'year':'month'
			})
		})


        $.get("/purchase/purchaseplan/listbynid?nid="+nid,function(res){
 	    	noTable=res.data;
	    });

    });

    function getMoreAfter(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,datas){//弹出框赋值回调
        if(fields=='productID'){
            var goodsid=$('#productID').val()
            $.get('/business/productactive/listzj2',{pcode:goodsid},function(res){
                if(res.data.length>0){
                    res.data.map((v,i)=>{
                        v.sCode=v.sBm
                        v.sName=v.name
                        v.sBz=v.remark
                        v.sNum=v.num
						v.vHw=datas.vHw
						v.vKq=datas.vKq
						v.rkGuid=datas.rkGuid
						v.rkBid=datas.rkBid
						v.gDepot=datas.gDepot
						v.guid=''
                        v.goodsAllocation=''
                    })
                }else{
                    res.data=[{sCode:datas.productCode,sName:datas.productName,sNum:datas.productNum,goodsAllocation:''}]
                }
				console.log("res.data",res.data)
                table.reload('dhtable', {data:res.data});
		    })
        }
    }
    

</script>

</body>
</html>